package com.sicheng.蓝桥.练习题;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/1/26 15:36
 */
public class 日期 {
    public static void main(String[] args) throws ParseException {
        main();
    }

    public static void main() throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date start = dateFormat.parse("2001-1-1");
        Date end = dateFormat.parse("2021-12-31");
        Calendar s = Calendar.getInstance();
        Calendar e = Calendar.getInstance();
        s.setTime(start);
        e.setTime(end);

        int res = 0;
        while (s.compareTo(e) <= 0) {
            int year = s.get(Calendar.YEAR);
            int month = s.get(Calendar.MONTH) + 1;
            int date = s.get(Calendar.DATE);

            if (check(year, month, date))
                res++;

            s.add(Calendar.DAY_OF_YEAR, 1);
        }
        System.out.println(res);

    }

    public static boolean check(int year, int month, int date) {
        int temp = add(String.valueOf(year)) + add(String.valueOf(month)) + add(String.valueOf(date));
        int sqrt = (int) Math.sqrt(temp);
        return sqrt*sqrt==temp;
    }

    public static int add(String num) {
        int sum = 0;
        for (int i = 0; i < num.length(); i++) {
            int tem = num.charAt(i) - '0';
            sum += tem;
        }
        return sum;


    }
}
